<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html >
<html lang="en">
<head>
<%@include file="../../../common/includeBaseSet.jsp" %>
<%@include file="../../../common/includeSystemSet.jsp" %>
<%@include file="../../../common/operation_forbid.jsp" %>
<%@include file="../../../common/jsVersion.jsp" %>
</head>
<body>
	<div class="page-content">
		    <div class="col-xs-12 panel panel-success" style="height:95%"> 
	         	 <div class="col-xs-6" style="width:100%">
	         	     <div class="form-group" style="text-align:center;margin-top: 3%">
						<label class="col-xs-3 control-label">问卷名称：</label>
	                    <input class="form-control" style="width:65%" type="text" name="name" id="name" maxlength="20"
	                    	placeholder=" 问卷名称不得超过20个字" onfocus="this.placeholder=''" onblur="this.placeholder='问卷名称不得超过20个字'"
	                    	value="${name}"/>
				     </div>
				     <div class="form-group" style="text-align:center;margin-top: 3%">
						<label class="col-xs-3 control-label">问卷描述：</label>
	                    <textarea class="form-control" style="width:65%;resize:none;" rows="4" maxlength="140" name="describe" id="describe"
	                    	placeholder="问卷描述不得超过140个字" onfocus="this.placeholder=''" onblur="this.placeholder='问卷描述不得超过140个字'">${describe}</textarea>
				     </div>
				     <div class="form-group" style="margin-top: 3%">
						<label class="col-xs-3 " style="padding-left:7%; width:99%;">创建人：${userName }</label>
				     </div>
				     <div class="form-group" style="margin-top: 3%">
						<label class="col-xs-3 " style="padding-left:7%; width:99%;">创建时间：${createTime }</label>
				     </div>
				     <div id="btnDiv" class="form-group" style="margin-top:13px;text-align:center;">
						<button type="button" onclick="add()" class="btn btn-default">确定</button>
						<button type="button" onclick="callback()" class="btn btn-link">取消</button>
				     </div>
				 </div>
		    </div>
	</div>	
</body>
<script type="text/javascript">
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	var btn = false; //判断是否已提交，默认未提交
	//新增问卷
	function add(){
		var name = $("#name").val();
		if(name == ""){
			layer.tips("请填写问卷名称", "#name", {tips: 3});
			return false;
		}
		if(name.length > 20){
			layer.tips("问卷名称不能超过20个字，当前字数为"+name.length+"个字", "#name", {tips: 3});
			return false;
		}
		var describe = $("#describe").val();
		if(describe.length > 140){
			layer.tips("问卷描述不能超过140个字，当前字数为"+describe.length+"个字", "#describe", {tips: 3});
			return false;
		}
		if(btn){
			layer.msg("正在保存中，请勿重复提交");
			return false;
		}
		btn = true; //将按钮状态修改为已提交
		//设置加载层
		var loadIndex = layer.load(1, {
	        shade: [0.1,'#fff'] //0.1透明度的白色背景
	    });
		$.ajax({
			type: 'post',
            url: '${jypath}/customer/questionnaireModel/copy',
            data:{
            	"copyId": "${copyId}", 
                "name": name,
                "questionnaireDescribe": describe
            },
            dataType: 'json',
            success: function(data){
            	layer.closeAll('loading'); //关闭加载层
            	btn = false; //执行完成后，将按钮状态修改回未提交
            	if(data.res == "1"){
            		layer.msg("复制模板成功");
            		//从编辑页打开复制窗口时，不刷新列表
            		if("e" != "${flag}"){
            			parent.loadQuestionnaireModel();
            		}
            		//延时执行执行回调方法并关闭窗口
                    setTimeout("callback()", 2000);
            	}else{
            		layer.msg(data.resMsg);
            	}
            }
		});
	}
	//执行回调方法并关闭窗口
	function callback(){
		parent.layer.close(index);
	}
	
</script>
</html>